<?php
 /*
  *微商城订单模型类
  *@author  <!--blakefan 1621743934@qq.com -->
  */
namespace Home\Model; 
use Think\Model;
class OrderModel
{
		/*
		 *获取购物车商品
		 *@param arra $cartid
		 *return array
		 */
		public function index($cartid=array())
		{
			
			$ids=!empty($cartid)?$cartid:'';
			if(empty($ids)){return '';}
			$result='';
			$cart=M('shipping_cart');
			 //获取购物车中的产品
			$where['id']=array('in',$ids);	
			$result['iteminfo']=$cart->where($where)->select();
			//计算商品总金额
			$result['countprice']=0;
			if(!empty($result['iteminfo'])){
				
				foreach($result['iteminfo'] as $key=>$value)
				{
					$result['countprice']+=round($value['totalprice'],2);
				}
			}
			//获取用户默认地址
			$uid=!empty($_SESSION['uid'])?$_SESSION['uid']:0;
			if(empty($uid)){return '';}
			$map['uid']=$uid;
			$map['isdefault']=1;
			$defaultAddress=M('user_address')->where($map)->select();
			if(!empty($defaultAddress))
			{
				$userinfo='';
				$province=M('area')->where('region_id=%d',$defaultAddress[0]['shengid'])->getField('region_name');
				$city=M('area')->where('region_id=%d',$defaultAddress[0]['shiid'])->getField('region_name');
				$county=M('area')->where('region_id=%d',$defaultAddress[0]['countyid'])->getField('region_name');
				$userinfo['province'] =$province;
				$userinfo['city'] =$city;
				$userinfo['county'] =$county;
				$userinfo['street']=$defaultAddress[0]['address'];
				$userinfo['phone']=$defaultAddress[0]['phone'];
				$userinfo['consignee']=$defaultAddress[0]['consignee'];
			}else
			{
				$userinfo='';
			}

			$result['userinfo']=$userinfo;
			//将购物车id save session
			$_SESSION['mycart']=$ids;
			
			return $result;

			

		}

}